import { _decorator, Component, Node } from 'cc';
import { Global } from '../Global';
const { ccclass, property } = _decorator;

export default class ahasdk {
    // 游戏加载完成打点上报
    public static gameLoadingCompleted() {
        console.log('游戏加载完成打点上报')
        if (!window.top['h5sdk']) {
            return
        }
        window.top['h5sdk'].gameLoadingCompleted();
    }
    // 展示激励广告
    public static showVideoAd(callFunc: Function, shibai: Function) {
        if (!window.top['h5sdk']) {
            callFunc && callFunc(); 
            return
        }
        window.top['h5sdk'].adBreak({
            type: "reward",
            name: "my_reward",
            beforeAd: function () {
                console.log("beforeAd");
            },
            afterAd: function () {
                console.log("afterAd");
            },
            adDismissed: function () {
                console.log("adDismissed");
                shibai && shibai();
            },
            adViewed: function () {
                console.log("adViewed");
                //callFunc && callFunc();
            },
            beforeReward: function (showAdFn) {
                console.log("beforeReward");
                setTimeout(() => {
                    showAdFn && showAdFn();
                }, 100);
            },
            adBreakDone: function (e) {
                console.log(e, "adBreakDone")//"viewed""frequencyCapped"
                if (e["breakStatus"] == "viewed") {
                    callFunc && callFunc();
                } else {
                    shibai && shibai();
                    Global.tips_action.show("No ads, Pls try again later");
                }
            }
        })
    }


    // 展示插屏广告
    public static showVideoAdChaPing(callFunc: Function, shibai: Function) {
      
        if (!window.top['h5sdk']) {
            return
        }
        window.top['h5sdk'].adBreak({
            type: "pause",
            name: "my_pause",
            beforeAd: function () {
                console.log("beforeAd");
            },
            afterAd: function () {
                console.log("afterAd");
            },
            adDismissed: function () {
                console.log("adDismissed");
                shibai && shibai();
            },
            adViewed: function () {
                console.log("adViewed");
                callFunc && callFunc();
            },
            beforeReward: function (showAdFn) {
                console.log("beforeReward");
                setTimeout(() => {
                    showAdFn && showAdFn();
                }, 100);
            },
            // adBreakDone: function (e) {
            //     console.log(e, "adBreakDone")
            //     callFunc && callFunc();
            // }
        })
    }


    // 展示插屏广告
    public static showVideoAdChaPing2(callFunc: Function, shibai: Function) {

        if (!window.top['h5sdk']) {
            return
        }

        window.top['h5sdk'].adBreak({
            type: "pause",
            name: "my_pause",
            beforeAd: function () {
                console.log("beforeAd");
            },
            afterAd: function () {
                callFunc && callFunc();
                console.log("afterAd");
            },
            adDismissed: function () {
                console.log("adDismissed");
                shibai && shibai();
            },
            adViewed: function () {
                console.log("adViewed");

            },
            beforeReward: function (showAdFn) {
                console.log("beforeReward");
                setTimeout(() => {
                    showAdFn && showAdFn();
                }, 100);
            },
            adBreakDone: function (e) {
                console.log(e, "adBreakDone")//"viewed""frequencyCapped"
                if (e["breakStatus"] == "viewed") {
                    //callFunc && callFunc();
                } else {
                    shibai && shibai();
                    Global.tips_action.show("No ads, Pls try again later");
                }
            }
        })
    }
}


